import React, { useEffect, useState } from 'react';
import { Upload, Button, message } from 'antd';
import { UploadOutlined } from '@ant-design/icons';
import { connect } from 'dva';
const theProps = (state) => {
    return {
        updataId: state.sample.updataId,
        samplemaps: state.fibsem.samplemaps
    }
}


function Updata(props) {
    const { dispatch, updataId, samplemaps } = props;
    console.log("props是什么", props)
    const prop = {
        action: 'http://10.89.101.39:9000/shale_porosity/upload/FibSem',
       // action: 'http://172.23.252.215:9000/shale_porosity/upload/FibSem',
        name: "files",
        onChange(info) {
            console.log(info.file, info.fileList, info.event, info);
            if (info.file.status !== 'uploading') {
                console.log(info.file, info.fileList, info.event);
            }
            if (info.file.status === 'done') {
                message.success(`${info.file.name} 文件上传成功`);
                // console.log(info.file, info.fileList,info.event);

                dispatch({
                    type: 'sample/remainSamplemaps',
                    payload: {
                        path: info.file.response.url,
                        sampleId: updataId,
                        name: info.file.name
                    }
                })
            } else if (info.file.status === 'error') {
                message.error(`${info.file.name} 文件上传失败`);
            }
        },
    };
    return (
        <div>
            <Upload {...prop} directory={false} showInfo={false}>
                <Button type="primary" style={{ marginLeft: '11.5em' }} icon={<UploadOutlined />}>上传文件</Button>
            </Upload>
            <div style={{ marginTop: '5px' }}>
                <span style={{ marginTop: '5px', marginLeft: '13em' }}>(请上传.ZIP)</span>
            </div>
        </div>

    )
}

export default connect(theProps, null)(Updata)
